package com.hst.capacity.facade.rest;

import cn.hutool.core.util.StrUtil;
import com.hst.capacity.application.biz.IntercityDispatchBiz;
import com.hst.capacity.domain.exception.BusinessException;
import com.hst.capacity.domain.model.request.intercity.dispatch.IcAddTaskParam;
import com.hst.capacity.domain.model.request.intercity.dispatch.IcDispatchDriverSearchParam;
import com.hst.capacity.domain.model.response.DefaultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

import static com.hst.capacity.domain.model.response.DefaultVO.success;

/**
 *  城际订单调度Controller
 *
 * */
@RequestMapping("/intercity/dispatch")
@RestController
public class IntercityDispatchController {
    @Autowired
    private IntercityDispatchBiz dispatchBiz;

    /**
     * 城市线路订单统计
     * @param param
     * @return
     */
    @PostMapping("/cityline/count")
    private DefaultVO cityLineCount(@RequestBody Map<String,String> param){
        String idFranchisee = param.get("idFranchisee");
        if (StrUtil.isEmpty(idFranchisee))
            throw new BusinessException(4001,"运营商ID[idFranchisee]不能为空");
        return success(dispatchBiz.cityLineCount(idFranchisee));
    }

    /**
     * 城市线路订单统计详细
     * @param param
     * @return
     */
    @PostMapping("/cityline/count/detail")
    private DefaultVO cityLineCountDetail(@RequestBody Map<String,String> param){
        String idFranchisee = param.get("idFranchisee");
        String idCityLine = param.get("idCityLine");
        if (StrUtil.isEmpty(idFranchisee))
            throw new BusinessException(4001,"运营商ID[idFranchisee]不能为空");
        return success(dispatchBiz.cityLineCountDetail(idFranchisee,idCityLine));
    }

    /**
     * 可待派单司机列表(开发中)
     * @param param
     * @return
     */
    @PostMapping("/driver/search")
    private DefaultVO icDispatchDriverSearch(@RequestBody @Valid IcDispatchDriverSearchParam param){
        return success(dispatchBiz.icDispatchDriverSearch(param));
    }

    /**
     * 可派单司机详细(开发中)
     * @param param
     * @return
     */
    @PostMapping("/driver/detail")
    private DefaultVO icDispatchDriverDetail(@RequestBody Map<String,String> param){
        String idDriver = param.get("idDriver");
        if (StrUtil.isEmpty(idDriver))
            throw new BusinessException(4001,"司机ID[idDriver]不能为空");
        return success(dispatchBiz.icDispatchDriverDetail(idDriver));
    }

    /**
     * 派单
     * @param param
     * @return
     */
    @PostMapping("/add/task")
    private DefaultVO icAddTask(@RequestBody@Valid IcAddTaskParam param){
        return success(dispatchBiz.icAddTask(param));
    }

}
